<template>
  <div>
    <home-header></home-header>
    <home-swiper :swiper-list="swiperList"></home-swiper>
    <home-icons :icon-list="iconList"></home-icons>
    <home-recommend :recommend-list="recommendList"></home-recommend>
    <home-weekend :weekend-list="weekendList"></home-weekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import { getHomeInfo } from '@/api/home'
import { mapGetters } from 'vuex'
export default {
  name: "Home",
  components:{
      HomeHeader,
      HomeSwiper,
      HomeIcons,
      HomeRecommend,
      HomeWeekend
  },
  data () {
    return {
      iconList:[],
      recommendList:[],
      weekendList:[],
      swiperList:[],
      lastCity:'',
    }
  },
  computed: {
    ...mapGetters(['city'])
  },
  mounted(){
    this.lastCity = this.city
    this.getInfo()
  },
  activated(){
    if(this.lastCity !== this.city){
      this.lastCity = this.city
      this.getInfo()

    }
  },
  methods:{
    getInfo(){
      var params = {
        city:this.$store.getters.city
      }
      getHomeInfo(params).then(response=>{
        if(response.data.ret){
          this.iconList = response.data.data.iconList
          this.recommendList = response.data.data.recommendList
          this.weekendList = response.data.data.weekendList
          this.swiperList = response.data.data.swiperList
        }
      })
    },
  }
};
</script>